package com.ijmacd.footballtracker;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class FootballTracker extends Activity {
	protected static final int GET_MATCH_REQUEST = 0;
	protected static final int GET_TEAM_REQUEST = 1;
	private Intent mServiceIntent;
	private Button viewMatchesBtn;
	private Button viewTeamsBtn;
	private Button viewWelcomeBtn;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_menu);

        viewMatchesBtn = (Button)findViewById(R.id.view_matches_btn);
        viewTeamsBtn = (Button)findViewById(R.id.view_teams_btn);
        viewWelcomeBtn = (Button)findViewById(R.id.view_welcome_btn);
        //suggestTeamBtn = (Button)findViewById(R.id.suggest_team_btn);

        viewMatchesBtn.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Intent matchesIntent = new Intent(Intent.ACTION_VIEW);
				matchesIntent.setType(Provider.Matches.CONTENT_TYPE);
				startActivity(matchesIntent);
			}
        });
        viewTeamsBtn.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Intent teamsIntent = new Intent(Intent.ACTION_VIEW);
				teamsIntent.setType(Provider.Teams.CONTENT_TYPE);
				startActivity(teamsIntent);
			}
        });
        viewWelcomeBtn.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Intent welcomeIntent = new Intent(FootballTracker.this, WelcomeActivity.class);
				startActivity(welcomeIntent);
			}
        });

        mServiceIntent = new Intent(this, DataFetcher.class);
        startService(mServiceIntent);
    }
    
    @Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	if(resultCode == Activity.RESULT_OK){
    		switch(requestCode){
    		case GET_MATCH_REQUEST:
    			startActivity(new Intent(Intent.ACTION_VIEW, data.getData()));
    			break;
    		case GET_TEAM_REQUEST:
    			startActivity(new Intent(Intent.ACTION_VIEW, data.getData()));
    			break;
    		}
    		Toast.makeText(this, "RESULT_OK", Toast.LENGTH_SHORT).show();
    	}else if(resultCode == Activity.RESULT_CANCELED){
    		Toast.makeText(this, "RESULT_CANCELED", Toast.LENGTH_SHORT).show();
    	}else if(resultCode == Activity.RESULT_FIRST_USER){
    		Toast.makeText(this, "RESULT_FIRST_USER", Toast.LENGTH_SHORT).show();
    	}
	}
}